//	ExampleGUI.java --- 

package fr.upmc.dtgui.example.robot;

import java.awt.HeadlessException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

//import fr.upmc.dtgui.example.gui.AnotherLittleRobotTeleoperationBoard;
//import fr.upmc.dtgui.example.gui.LittleRobotTeleoperationBoard;
import fr.upmc.dtgui.gui.RobotTeleoperationBoard;
import fr.upmc.dtgui.gui.SensorDataReceptorInterface;
import fr.upmc.dtgui.gui.TeleoperationGUI;
import fr.upmc.dtgui.robot.InstrumentedRobot;

import fr.upmc.dtgui.tests.LittleRobot;
//import fr.upmc.dtgui.tests.AnotherLittleRobot;

public class ExampleGUI extends TeleoperationGUI {

	private static final long serialVersionUID = 1L;

	public ExampleGUI(
		String panelName,
		int absoluteX,
		int absoluteY,
		int relativeX,
		int relativeY,
		int controlRadius,
		int sizeX,
		int sizeY
		) throws HeadlessException
	{
		super(panelName, absoluteX, absoluteY, relativeX, relativeY,
												controlRadius, sizeX, sizeY);
	}

	public RobotTeleoperationBoard	createBoard(InstrumentedRobot lr) {
		RobotTeleoperationBoard board = null ;
		try {
		    Class<?> boardClass = Class.forName(lr.getClass().getSimpleName() + "TeleoperationBoard");
		    Class<?> partypes[] = new Class[2];
		    partypes[0] = TeleoperationGUI.class;
		    partypes[1] = int.class;
		    Constructor<?> boardConstructor = boardClass.getConstructor(partypes);
			Object arglist[] = new Object[2];
			arglist[0] = this;
			arglist[1] = this.sizeX -50;
			board = (RobotTeleoperationBoard) boardConstructor.newInstance(arglist);
		}
		catch(ClassNotFoundException e) {
			// TODO: create an exception type
			System.out.println("Unknown type of robot : " +
									lr.getClass().getCanonicalName()) ;
			e.printStackTrace();
			System.exit(1) ;
		}
		catch(Exception e) {
			e.printStackTrace();
		}
		return board ;
	}

	public SensorDataReceptorInterface createSensorDataReceptor(
		InstrumentedRobot lr,
		RobotTeleoperationBoard board
		)
	{
		
		SensorDataReceptorInterface sdr = null ;
		try{
			Class.forName(lr.getClass().getSimpleName()+"TeleoperationBoard$SensorDataReceptor");
			
			
			sdr = board.makeSensorDataReceptor(
						this.positionDisplay, lr.getSensorDataQueue(),
						this.absoluteX, this.absoluteY, this.controlRadius) ;
			
			
		} catch(Exception e) {
			// TODO: create an exception type
			System.out.println("Unknown type of robot : " +
											lr.getClass().getCanonicalName()) ;
			e.printStackTrace();
			System.exit(1) ;
		}
		return sdr ;
	}
}

// $Id$